// gui/GuiSelectable.cpp

#include "GuiSelectable.h"
#include "GuiHotSpot.h"

TypeId GUI::GuiSelectable::s_TypeId = "GuiSelectable";

using namespace GUI;

bool GuiSelectable::SetFocus(float fX, float fY)
{
	bool bInHotSpot = false;

	if (m_pHotSpot && IsHighlightable())
	{
		bInHotSpot = m_pHotSpot->IsInside(fX, fY);

		if (bInHotSpot != IsActive())
		{
			bInHotSpot = OnHighlight(bInHotSpot);
		}
	}

	return bInHotSpot;
}

bool GuiSelectable::IsInHotSpot(float fX, float fY)
{
	bool bInside = false;

	if (IsHighlightable() && m_pHotSpot)
		bInside = m_pHotSpot->IsInside(fX, fY);

	return bInside;
}

bool GuiSelectable::OnHighlight(bool bHighlighted)
{
	bool bSuccess = IsHighlightable() || (IsHighlightable() == bHighlighted);

	if (bHighlighted != IsActive())
		SetActive(bHighlighted);

	return bSuccess;
}